package common

import (
	"jlpay-sdk-go/pkg/jlpay/core"
	"jlpay-sdk-go/pkg/jlpay/models"
)

// ==================== 预授权查询请求 ====================

// PreAuthQueryRequest 预授权查询请求
type PreAuthQueryRequest struct {
	models.OrgBaseRequest
	// MchID 商户号
	MchID string `json:"mch_id,omitempty"`
	// OutTradeNo 外部订单号
	OutTradeNo string `json:"out_trade_no,omitempty"`
	// TransactionID 平台订单号
	TransactionID string `json:"transaction_id,omitempty"`
	// 原始请求映射数据
	rawRequestMap map[string]interface{} `json:"-"`
}

// NewPreAuthQueryRequest 创建预授权查询请求
func NewPreAuthQueryRequest() *PreAuthQueryRequest {
	return &PreAuthQueryRequest{}
}

// SetMchID 设置商户号
func (r *PreAuthQueryRequest) SetMchID(mchID string) *PreAuthQueryRequest {
	r.MchID = mchID
	return r
}

// SetOutTradeNo 设置外部订单号
func (r *PreAuthQueryRequest) SetOutTradeNo(outTradeNo string) *PreAuthQueryRequest {
	r.OutTradeNo = outTradeNo
	return r
}

// SetTransactionID 设置平台订单号
func (r *PreAuthQueryRequest) SetTransactionID(transactionID string) *PreAuthQueryRequest {
	r.TransactionID = transactionID
	return r
}

// SetRawRequestMap 设置原始请求映射数据
func (r *PreAuthQueryRequest) SetRawRequestMap(rawMap map[string]interface{}) *PreAuthQueryRequest {
	r.rawRequestMap = rawMap
	return r
}

// GetRawMap 获取原始映射数据
func (r *PreAuthQueryRequest) GetRawMap() (map[string]interface{}, bool) {
	return r.rawRequestMap, r.rawRequestMap != nil
}

// ToMap 转换为map
func (r *PreAuthQueryRequest) ToMap() (map[string]interface{}, error) {
	// 如果有原始映射数据，直接返回
	if rawMap, exists := r.GetRawMap(); exists {
		return rawMap, nil
	}

	// 构建基础请求数据
	requestMap := make(map[string]interface{})

	// 添加基础字段
	if r.MchID != "" {
		requestMap["mch_id"] = r.MchID
	}
	if r.OutTradeNo != "" {
		requestMap["out_trade_no"] = r.OutTradeNo
	}
	if r.TransactionID != "" {
		requestMap["transaction_id"] = r.TransactionID
	}

	// 合并基础请求数据
	baseMap, err := r.OrgBaseRequest.ToMap()
	if err != nil {
		return nil, err
	}

	for k, v := range baseMap {
		requestMap[k] = v
	}

	return requestMap, nil
}

// CheckRequiredParams 检查必需参数
func (r *PreAuthQueryRequest) CheckRequiredParams(config *core.Config) error {
	return r.OrgBaseRequest.CheckRequiredParams(config)
}

// ==================== 预授权查询响应 ====================

// PreAuthQueryResponse 预授权查询响应
type PreAuthQueryResponse struct {
	models.StandardResponse
	// Status 状态 1：待确认2：成功3：失败
	Status string `json:"status,omitempty"`
	// MchID 商户号
	MchID string `json:"mch_id,omitempty"`
	// TransactionID 平台订单号
	TransactionID string `json:"transaction_id,omitempty"`
	// OutTradeNo 外部订单号
	OutTradeNo string `json:"out_trade_no,omitempty"`
	// ChnTransactionID 渠道订单号
	ChnTransactionID string `json:"chn_transaction_id,omitempty"`
	// OrderTime 订单时间
	OrderTime string `json:"order_time,omitempty"`
	// PayType 交易类型
	PayType string `json:"pay_type,omitempty"`
	// TotalFee 交易金额
	TotalFee interface{} `json:"total_fee,omitempty"`
	// TransTime 交易时间
	TransTime string `json:"trans_time,omitempty"`
	// GuaranteeAuthCode 担保授权码
	GuaranteeAuthCode string `json:"guarantee_auth_code,omitempty"`
}

// NewPreAuthQueryResponse 创建预授权查询响应
func NewPreAuthQueryResponse() *PreAuthQueryResponse {
	return &PreAuthQueryResponse{}
}

// ==================== 预授权完成请求 ====================

// PreAuthCompleteRequest 预授权完成请求
type PreAuthCompleteRequest struct {
	models.OrgBaseRequest
	// MchID 商户号
	MchID string `json:"mch_id,omitempty"`
	// TermNo 终端号
	TermNo string `json:"term_no,omitempty"`
	// PayType 交易类型
	PayType string `json:"pay_type,omitempty"`
	// OutTradeNo 外部订单号
	OutTradeNo string `json:"out_trade_no,omitempty"`
	// OriOutTradeNo 原外部订单号
	OriOutTradeNo string `json:"ori_out_trade_no,omitempty"`
	// OriTransactionID 原平台订单号
	OriTransactionID string `json:"ori_transaction_id,omitempty"`
	// GuaranteeAuthCode 担保授权码
	GuaranteeAuthCode string `json:"guarantee_auth_code,omitempty"`
	// TotalFee 交易金额
	TotalFee string `json:"total_fee,omitempty"`
	// Remark 备注
	Remark string `json:"remark,omitempty"`
	// DeviceInfo 终端设备号
	DeviceInfo string `json:"device_info,omitempty"`
	// MchCreateIP 商户IP
	MchCreateIP string `json:"mch_create_ip,omitempty"`
	// TransAddress 交易地址
	TransAddress string `json:"trans_address,omitempty"`
	// AreaCode 交易地区码
	AreaCode string `json:"area_code,omitempty"`
	// Longitude 经度
	Longitude string `json:"longitude,omitempty"`
	// Latitude 纬度
	Latitude string `json:"latitude,omitempty"`
	// 原始请求映射数据
	rawRequestMap map[string]interface{} `json:"-"`
}

// NewPreAuthCompleteRequest 创建预授权完成请求
func NewPreAuthCompleteRequest() *PreAuthCompleteRequest {
	return &PreAuthCompleteRequest{}
}

// SetMchID 设置商户号
func (r *PreAuthCompleteRequest) SetMchID(mchID string) *PreAuthCompleteRequest {
	r.MchID = mchID
	return r
}

// SetTermNo 设置终端号
func (r *PreAuthCompleteRequest) SetTermNo(termNo string) *PreAuthCompleteRequest {
	r.TermNo = termNo
	return r
}

// SetPayType 设置交易类型
func (r *PreAuthCompleteRequest) SetPayType(payType string) *PreAuthCompleteRequest {
	r.PayType = payType
	return r
}

// SetOutTradeNo 设置外部订单号
func (r *PreAuthCompleteRequest) SetOutTradeNo(outTradeNo string) *PreAuthCompleteRequest {
	r.OutTradeNo = outTradeNo
	return r
}

// SetOriOutTradeNo 设置原外部订单号
func (r *PreAuthCompleteRequest) SetOriOutTradeNo(oriOutTradeNo string) *PreAuthCompleteRequest {
	r.OriOutTradeNo = oriOutTradeNo
	return r
}

// SetOriTransactionID 设置原平台订单号
func (r *PreAuthCompleteRequest) SetOriTransactionID(oriTransactionID string) *PreAuthCompleteRequest {
	r.OriTransactionID = oriTransactionID
	return r
}

// SetGuaranteeAuthCode 设置担保授权码
func (r *PreAuthCompleteRequest) SetGuaranteeAuthCode(guaranteeAuthCode string) *PreAuthCompleteRequest {
	r.GuaranteeAuthCode = guaranteeAuthCode
	return r
}

// SetTotalFee 设置交易金额
func (r *PreAuthCompleteRequest) SetTotalFee(totalFee string) *PreAuthCompleteRequest {
	r.TotalFee = totalFee
	return r
}

// SetRemark 设置备注
func (r *PreAuthCompleteRequest) SetRemark(remark string) *PreAuthCompleteRequest {
	r.Remark = remark
	return r
}

// SetDeviceInfo 设置终端设备号
func (r *PreAuthCompleteRequest) SetDeviceInfo(deviceInfo string) *PreAuthCompleteRequest {
	r.DeviceInfo = deviceInfo
	return r
}

// SetMchCreateIP 设置商户IP
func (r *PreAuthCompleteRequest) SetMchCreateIP(mchCreateIP string) *PreAuthCompleteRequest {
	r.MchCreateIP = mchCreateIP
	return r
}

// SetTransAddress 设置交易地址
func (r *PreAuthCompleteRequest) SetTransAddress(transAddress string) *PreAuthCompleteRequest {
	r.TransAddress = transAddress
	return r
}

// SetAreaCode 设置交易地区码
func (r *PreAuthCompleteRequest) SetAreaCode(areaCode string) *PreAuthCompleteRequest {
	r.AreaCode = areaCode
	return r
}

// SetLongitude 设置经度
func (r *PreAuthCompleteRequest) SetLongitude(longitude string) *PreAuthCompleteRequest {
	r.Longitude = longitude
	return r
}

// SetLatitude 设置纬度
func (r *PreAuthCompleteRequest) SetLatitude(latitude string) *PreAuthCompleteRequest {
	r.Latitude = latitude
	return r
}

// SetRawRequestMap 设置原始请求映射数据
func (r *PreAuthCompleteRequest) SetRawRequestMap(rawMap map[string]interface{}) *PreAuthCompleteRequest {
	r.rawRequestMap = rawMap
	return r
}

// GetRawMap 获取原始映射数据
func (r *PreAuthCompleteRequest) GetRawMap() (map[string]interface{}, bool) {
	return r.rawRequestMap, r.rawRequestMap != nil
}

// ToMap 转换为map
func (r *PreAuthCompleteRequest) ToMap() (map[string]interface{}, error) {
	// 如果有原始映射数据，直接返回
	if rawMap, exists := r.GetRawMap(); exists {
		return rawMap, nil
	}

	// 构建基础请求数据
	requestMap := make(map[string]interface{})

	// 添加基础字段
	if r.MchID != "" {
		requestMap["mch_id"] = r.MchID
	}
	if r.TermNo != "" {
		requestMap["term_no"] = r.TermNo
	}
	if r.PayType != "" {
		requestMap["pay_type"] = r.PayType
	}
	if r.OutTradeNo != "" {
		requestMap["out_trade_no"] = r.OutTradeNo
	}
	if r.OriOutTradeNo != "" {
		requestMap["ori_out_trade_no"] = r.OriOutTradeNo
	}
	if r.OriTransactionID != "" {
		requestMap["ori_transaction_id"] = r.OriTransactionID
	}
	if r.GuaranteeAuthCode != "" {
		requestMap["guarantee_auth_code"] = r.GuaranteeAuthCode
	}
	if r.TotalFee != "" {
		requestMap["total_fee"] = r.TotalFee
	}
	if r.Remark != "" {
		requestMap["remark"] = r.Remark
	}
	if r.DeviceInfo != "" {
		requestMap["device_info"] = r.DeviceInfo
	}
	if r.MchCreateIP != "" {
		requestMap["mch_create_ip"] = r.MchCreateIP
	}
	if r.TransAddress != "" {
		requestMap["trans_address"] = r.TransAddress
	}
	if r.AreaCode != "" {
		requestMap["area_code"] = r.AreaCode
	}
	if r.Longitude != "" {
		requestMap["longitude"] = r.Longitude
	}
	if r.Latitude != "" {
		requestMap["latitude"] = r.Latitude
	}

	// 合并基础请求数据
	baseMap, err := r.OrgBaseRequest.ToMap()
	if err != nil {
		return nil, err
	}

	for k, v := range baseMap {
		requestMap[k] = v
	}

	return requestMap, nil
}

// CheckRequiredParams 检查必需参数
func (r *PreAuthCompleteRequest) CheckRequiredParams(config *core.Config) error {
	return r.OrgBaseRequest.CheckRequiredParams(config)
}

// ==================== 预授权完成响应 ====================

// PreAuthCompleteResponse 预授权完成响应
type PreAuthCompleteResponse struct {
	models.StandardResponse
	// Status 状态 2：成功 3：失败
	Status string `json:"status,omitempty"`
	// MchID 商户号
	MchID string `json:"mch_id,omitempty"`
	// TransactionID 平台订单号
	TransactionID string `json:"transaction_id,omitempty"`
	// OutTradeNo 外部订单号
	OutTradeNo string `json:"out_trade_no,omitempty"`
	// OriOutTradeNo 原外部订单号
	OriOutTradeNo string `json:"ori_out_trade_no,omitempty"`
	// OriTransactionID 原平台订单号
	OriTransactionID string `json:"ori_transaction_id,omitempty"`
	// OrderTime 订单时间
	OrderTime string `json:"order_time,omitempty"`
	// PayType 交易类型
	PayType string `json:"pay_type,omitempty"`
	// TotalFee 交易金额
	TotalFee interface{} `json:"total_fee,omitempty"`
	// TransTime 交易时间
	TransTime string `json:"trans_time,omitempty"`
}

// NewPreAuthCompleteResponse 创建预授权完成响应
func NewPreAuthCompleteResponse() *PreAuthCompleteResponse {
	return &PreAuthCompleteResponse{}
}

// ==================== 预授权关闭请求 ====================

// PreAuthCloseRequest 预授权关闭请求
type PreAuthCloseRequest struct {
	models.OrgBaseRequest
	// MchID 商户号
	MchID string `json:"mch_id,omitempty"`
	// TermNo 终端号
	TermNo string `json:"term_no,omitempty"`
	// PayType 交易类型
	PayType string `json:"pay_type,omitempty"`
	// OutTradeNo 外部订单号
	OutTradeNo string `json:"out_trade_no,omitempty"`
	// OriOutTradeNo 原外部订单号
	OriOutTradeNo string `json:"ori_out_trade_no,omitempty"`
	// OriTransactionID 原平台订单号
	OriTransactionID string `json:"ori_transaction_id,omitempty"`
	// GuaranteeAuthCode 担保授权码
	GuaranteeAuthCode string `json:"guarantee_auth_code,omitempty"`
	// TotalFee 交易金额
	TotalFee string `json:"total_fee,omitempty"`
	// Remark 备注
	Remark string `json:"remark,omitempty"`
	// DeviceInfo 终端设备号
	DeviceInfo string `json:"device_info,omitempty"`
	// MchCreateIP 商户IP
	MchCreateIP string `json:"mch_create_ip,omitempty"`
	// TransAddress 交易地址
	TransAddress string `json:"trans_address,omitempty"`
	// AreaCode 交易地区码
	AreaCode string `json:"area_code,omitempty"`
	// Longitude 经度
	Longitude string `json:"longitude,omitempty"`
	// Latitude 纬度
	Latitude string `json:"latitude,omitempty"`
	// 原始请求映射数据
	rawRequestMap map[string]interface{} `json:"-"`
}

// NewPreAuthCloseRequest 创建预授权关闭请求
func NewPreAuthCloseRequest() *PreAuthCloseRequest {
	return &PreAuthCloseRequest{}
}

// SetMchID 设置商户号
func (r *PreAuthCloseRequest) SetMchID(mchID string) *PreAuthCloseRequest {
	r.MchID = mchID
	return r
}

// SetTermNo 设置终端号
func (r *PreAuthCloseRequest) SetTermNo(termNo string) *PreAuthCloseRequest {
	r.TermNo = termNo
	return r
}

// SetPayType 设置交易类型
func (r *PreAuthCloseRequest) SetPayType(payType string) *PreAuthCloseRequest {
	r.PayType = payType
	return r
}

// SetOutTradeNo 设置外部订单号
func (r *PreAuthCloseRequest) SetOutTradeNo(outTradeNo string) *PreAuthCloseRequest {
	r.OutTradeNo = outTradeNo
	return r
}

// SetOriOutTradeNo 设置原外部订单号
func (r *PreAuthCloseRequest) SetOriOutTradeNo(oriOutTradeNo string) *PreAuthCloseRequest {
	r.OriOutTradeNo = oriOutTradeNo
	return r
}

// SetOriTransactionID 设置原平台订单号
func (r *PreAuthCloseRequest) SetOriTransactionID(oriTransactionID string) *PreAuthCloseRequest {
	r.OriTransactionID = oriTransactionID
	return r
}

// SetGuaranteeAuthCode 设置担保授权码
func (r *PreAuthCloseRequest) SetGuaranteeAuthCode(guaranteeAuthCode string) *PreAuthCloseRequest {
	r.GuaranteeAuthCode = guaranteeAuthCode
	return r
}

// SetTotalFee 设置交易金额
func (r *PreAuthCloseRequest) SetTotalFee(totalFee string) *PreAuthCloseRequest {
	r.TotalFee = totalFee
	return r
}

// SetRemark 设置备注
func (r *PreAuthCloseRequest) SetRemark(remark string) *PreAuthCloseRequest {
	r.Remark = remark
	return r
}

// SetDeviceInfo 设置终端设备号
func (r *PreAuthCloseRequest) SetDeviceInfo(deviceInfo string) *PreAuthCloseRequest {
	r.DeviceInfo = deviceInfo
	return r
}

// SetMchCreateIP 设置商户IP
func (r *PreAuthCloseRequest) SetMchCreateIP(mchCreateIP string) *PreAuthCloseRequest {
	r.MchCreateIP = mchCreateIP
	return r
}

// SetTransAddress 设置交易地址
func (r *PreAuthCloseRequest) SetTransAddress(transAddress string) *PreAuthCloseRequest {
	r.TransAddress = transAddress
	return r
}

// SetAreaCode 设置交易地区码
func (r *PreAuthCloseRequest) SetAreaCode(areaCode string) *PreAuthCloseRequest {
	r.AreaCode = areaCode
	return r
}

// SetLongitude 设置经度
func (r *PreAuthCloseRequest) SetLongitude(longitude string) *PreAuthCloseRequest {
	r.Longitude = longitude
	return r
}

// SetLatitude 设置纬度
func (r *PreAuthCloseRequest) SetLatitude(latitude string) *PreAuthCloseRequest {
	r.Latitude = latitude
	return r
}

// SetRawRequestMap 设置原始请求映射数据
func (r *PreAuthCloseRequest) SetRawRequestMap(rawMap map[string]interface{}) *PreAuthCloseRequest {
	r.rawRequestMap = rawMap
	return r
}

// GetRawMap 获取原始映射数据
func (r *PreAuthCloseRequest) GetRawMap() (map[string]interface{}, bool) {
	return r.rawRequestMap, r.rawRequestMap != nil
}

// ToMap 转换为map
func (r *PreAuthCloseRequest) ToMap() (map[string]interface{}, error) {
	// 如果有原始映射数据，直接返回
	if rawMap, exists := r.GetRawMap(); exists {
		return rawMap, nil
	}

	// 构建基础请求数据
	requestMap := make(map[string]interface{})

	// 添加基础字段
	if r.MchID != "" {
		requestMap["mch_id"] = r.MchID
	}
	if r.TermNo != "" {
		requestMap["term_no"] = r.TermNo
	}
	if r.PayType != "" {
		requestMap["pay_type"] = r.PayType
	}
	if r.OutTradeNo != "" {
		requestMap["out_trade_no"] = r.OutTradeNo
	}
	if r.OriOutTradeNo != "" {
		requestMap["ori_out_trade_no"] = r.OriOutTradeNo
	}
	if r.OriTransactionID != "" {
		requestMap["ori_transaction_id"] = r.OriTransactionID
	}
	if r.GuaranteeAuthCode != "" {
		requestMap["guarantee_auth_code"] = r.GuaranteeAuthCode
	}
	if r.TotalFee != "" {
		requestMap["total_fee"] = r.TotalFee
	}
	if r.Remark != "" {
		requestMap["remark"] = r.Remark
	}
	if r.DeviceInfo != "" {
		requestMap["device_info"] = r.DeviceInfo
	}
	if r.MchCreateIP != "" {
		requestMap["mch_create_ip"] = r.MchCreateIP
	}
	if r.TransAddress != "" {
		requestMap["trans_address"] = r.TransAddress
	}
	if r.AreaCode != "" {
		requestMap["area_code"] = r.AreaCode
	}
	if r.Longitude != "" {
		requestMap["longitude"] = r.Longitude
	}
	if r.Latitude != "" {
		requestMap["latitude"] = r.Latitude
	}

	// 合并基础请求数据
	baseMap, err := r.OrgBaseRequest.ToMap()
	if err != nil {
		return nil, err
	}

	for k, v := range baseMap {
		requestMap[k] = v
	}

	return requestMap, nil
}

// CheckRequiredParams 检查必需参数
func (r *PreAuthCloseRequest) CheckRequiredParams(config *core.Config) error {
	return r.OrgBaseRequest.CheckRequiredParams(config)
}

// ==================== 预授权关闭响应 ====================

// PreAuthCloseResponse 预授权关闭响应
type PreAuthCloseResponse struct {
	models.StandardResponse
	// Status 状态 2：成功 3：失败
	Status string `json:"status,omitempty"`
	// MchID 商户号
	MchID string `json:"mch_id,omitempty"`
	// TransactionID 平台订单号
	TransactionID string `json:"transaction_id,omitempty"`
	// OutTradeNo 外部订单号
	OutTradeNo string `json:"out_trade_no,omitempty"`
	// OriOutTradeNo 原外部订单号
	OriOutTradeNo string `json:"ori_out_trade_no,omitempty"`
	// OriTransactionID 原平台订单号
	OriTransactionID string `json:"ori_transaction_id,omitempty"`
	// OrderTime 订单时间
	OrderTime string `json:"order_time,omitempty"`
	// PayType 交易类型
	PayType string `json:"pay_type,omitempty"`
	// TotalFee 交易金额
	TotalFee interface{} `json:"total_fee,omitempty"`
	// TransTime 交易时间
	TransTime string `json:"trans_time,omitempty"`
}

// NewPreAuthCloseResponse 创建预授权关闭响应
func NewPreAuthCloseResponse() *PreAuthCloseResponse {
	return &PreAuthCloseResponse{}
}

// ==================== 预授权撤销请求 ====================

// PreAuthRevokeRequest 预授权撤销请求
type PreAuthRevokeRequest struct {
	models.OrgBaseRequest
	// MchID 商户号
	MchID string `json:"mch_id,omitempty"`
	// TermNo 终端号
	TermNo string `json:"term_no,omitempty"`
	// PayType 交易类型
	PayType string `json:"pay_type,omitempty"`
	// OutTradeNo 外部订单号
	OutTradeNo string `json:"out_trade_no,omitempty"`
	// OriOutTradeNo 原外部订单号
	OriOutTradeNo string `json:"ori_out_trade_no,omitempty"`
	// OriTransactionID 原平台订单号
	OriTransactionID string `json:"ori_transaction_id,omitempty"`
	// GuaranteeAuthCode 担保授权码
	GuaranteeAuthCode string `json:"guarantee_auth_code,omitempty"`
	// TotalFee 交易金额
	TotalFee string `json:"total_fee,omitempty"`
	// Remark 备注
	Remark string `json:"remark,omitempty"`
	// DeviceInfo 终端设备号
	DeviceInfo string `json:"device_info,omitempty"`
	// MchCreateIP 商户IP
	MchCreateIP string `json:"mch_create_ip,omitempty"`
	// TransAddress 交易地址
	TransAddress string `json:"trans_address,omitempty"`
	// AreaCode 交易地区码
	AreaCode string `json:"area_code,omitempty"`
	// Longitude 经度
	Longitude string `json:"longitude,omitempty"`
	// Latitude 纬度
	Latitude string `json:"latitude,omitempty"`
	// 原始请求映射数据
	rawRequestMap map[string]interface{} `json:"-"`
}

// NewPreAuthRevokeRequest 创建预授权撤销请求
func NewPreAuthRevokeRequest() *PreAuthRevokeRequest {
	return &PreAuthRevokeRequest{}
}

// SetMchID 设置商户号
func (r *PreAuthRevokeRequest) SetMchID(mchID string) *PreAuthRevokeRequest {
	r.MchID = mchID
	return r
}

// SetTermNo 设置终端号
func (r *PreAuthRevokeRequest) SetTermNo(termNo string) *PreAuthRevokeRequest {
	r.TermNo = termNo
	return r
}

// SetPayType 设置交易类型
func (r *PreAuthRevokeRequest) SetPayType(payType string) *PreAuthRevokeRequest {
	r.PayType = payType
	return r
}

// SetOutTradeNo 设置外部订单号
func (r *PreAuthRevokeRequest) SetOutTradeNo(outTradeNo string) *PreAuthRevokeRequest {
	r.OutTradeNo = outTradeNo
	return r
}

// SetOriOutTradeNo 设置原外部订单号
func (r *PreAuthRevokeRequest) SetOriOutTradeNo(oriOutTradeNo string) *PreAuthRevokeRequest {
	r.OriOutTradeNo = oriOutTradeNo
	return r
}

// SetOriTransactionID 设置原平台订单号
func (r *PreAuthRevokeRequest) SetOriTransactionID(oriTransactionID string) *PreAuthRevokeRequest {
	r.OriTransactionID = oriTransactionID
	return r
}

// SetGuaranteeAuthCode 设置担保授权码
func (r *PreAuthRevokeRequest) SetGuaranteeAuthCode(guaranteeAuthCode string) *PreAuthRevokeRequest {
	r.GuaranteeAuthCode = guaranteeAuthCode
	return r
}

// SetTotalFee 设置交易金额
func (r *PreAuthRevokeRequest) SetTotalFee(totalFee string) *PreAuthRevokeRequest {
	r.TotalFee = totalFee
	return r
}

// SetRemark 设置备注
func (r *PreAuthRevokeRequest) SetRemark(remark string) *PreAuthRevokeRequest {
	r.Remark = remark
	return r
}

// SetDeviceInfo 设置终端设备号
func (r *PreAuthRevokeRequest) SetDeviceInfo(deviceInfo string) *PreAuthRevokeRequest {
	r.DeviceInfo = deviceInfo
	return r
}

// SetMchCreateIP 设置商户IP
func (r *PreAuthRevokeRequest) SetMchCreateIP(mchCreateIP string) *PreAuthRevokeRequest {
	r.MchCreateIP = mchCreateIP
	return r
}

// SetTransAddress 设置交易地址
func (r *PreAuthRevokeRequest) SetTransAddress(transAddress string) *PreAuthRevokeRequest {
	r.TransAddress = transAddress
	return r
}

// SetAreaCode 设置交易地区码
func (r *PreAuthRevokeRequest) SetAreaCode(areaCode string) *PreAuthRevokeRequest {
	r.AreaCode = areaCode
	return r
}

// SetLongitude 设置经度
func (r *PreAuthRevokeRequest) SetLongitude(longitude string) *PreAuthRevokeRequest {
	r.Longitude = longitude
	return r
}

// SetLatitude 设置纬度
func (r *PreAuthRevokeRequest) SetLatitude(latitude string) *PreAuthRevokeRequest {
	r.Latitude = latitude
	return r
}

// SetRawRequestMap 设置原始请求映射数据
func (r *PreAuthRevokeRequest) SetRawRequestMap(rawMap map[string]interface{}) *PreAuthRevokeRequest {
	r.rawRequestMap = rawMap
	return r
}

// GetRawMap 获取原始映射数据
func (r *PreAuthRevokeRequest) GetRawMap() (map[string]interface{}, bool) {
	return r.rawRequestMap, r.rawRequestMap != nil
}

// ToMap 转换为map
func (r *PreAuthRevokeRequest) ToMap() (map[string]interface{}, error) {
	// 如果有原始映射数据，直接返回
	if rawMap, exists := r.GetRawMap(); exists {
		return rawMap, nil
	}

	// 构建基础请求数据
	requestMap := make(map[string]interface{})

	// 添加基础字段
	if r.MchID != "" {
		requestMap["mch_id"] = r.MchID
	}
	if r.TermNo != "" {
		requestMap["term_no"] = r.TermNo
	}
	if r.PayType != "" {
		requestMap["pay_type"] = r.PayType
	}
	if r.OutTradeNo != "" {
		requestMap["out_trade_no"] = r.OutTradeNo
	}
	if r.OriOutTradeNo != "" {
		requestMap["ori_out_trade_no"] = r.OriOutTradeNo
	}
	if r.OriTransactionID != "" {
		requestMap["ori_transaction_id"] = r.OriTransactionID
	}
	if r.GuaranteeAuthCode != "" {
		requestMap["guarantee_auth_code"] = r.GuaranteeAuthCode
	}
	if r.TotalFee != "" {
		requestMap["total_fee"] = r.TotalFee
	}
	if r.Remark != "" {
		requestMap["remark"] = r.Remark
	}
	if r.DeviceInfo != "" {
		requestMap["device_info"] = r.DeviceInfo
	}
	if r.MchCreateIP != "" {
		requestMap["mch_create_ip"] = r.MchCreateIP
	}
	if r.TransAddress != "" {
		requestMap["trans_address"] = r.TransAddress
	}
	if r.AreaCode != "" {
		requestMap["area_code"] = r.AreaCode
	}
	if r.Longitude != "" {
		requestMap["longitude"] = r.Longitude
	}
	if r.Latitude != "" {
		requestMap["latitude"] = r.Latitude
	}

	// 合并基础请求数据
	baseMap, err := r.OrgBaseRequest.ToMap()
	if err != nil {
		return nil, err
	}

	for k, v := range baseMap {
		requestMap[k] = v
	}

	return requestMap, nil
}

// CheckRequiredParams 检查必需参数
func (r *PreAuthRevokeRequest) CheckRequiredParams(config *core.Config) error {
	return r.OrgBaseRequest.CheckRequiredParams(config)
}

// ==================== 预授权撤销响应 ====================

// PreAuthRevokeResponse 预授权撤销响应
type PreAuthRevokeResponse struct {
	models.StandardResponse
	// Status 状态 2：成功 3：失败
	Status string `json:"status,omitempty"`
	// MchID 商户号
	MchID string `json:"mch_id,omitempty"`
	// TransactionID 平台订单号
	TransactionID string `json:"transaction_id,omitempty"`
	// OutTradeNo 外部订单号
	OutTradeNo string `json:"out_trade_no,omitempty"`
	// OriOutTradeNo 原外部订单号
	OriOutTradeNo string `json:"ori_out_trade_no,omitempty"`
	// OriTransactionID 原平台订单号
	OriTransactionID string `json:"ori_transaction_id,omitempty"`
	// OrderTime 订单时间
	OrderTime string `json:"order_time,omitempty"`
	// PayType 交易类型
	PayType string `json:"pay_type,omitempty"`
	// TotalFee 交易金额
	TotalFee interface{} `json:"total_fee,omitempty"`
	// TransTime 交易时间
	TransTime string `json:"trans_time,omitempty"`
}

// NewPreAuthRevokeResponse 创建预授权撤销响应
func NewPreAuthRevokeResponse() *PreAuthRevokeResponse {
	return &PreAuthRevokeResponse{}
}

// ==================== 预授权完成退款请求 ====================

// AuthCompleteRefundRequest 预授权完成退款请求
type AuthCompleteRefundRequest struct {
	models.OrgBaseRequest
	// MchID 商户号
	MchID string `json:"mch_id,omitempty"`
	// TermNo 终端号
	TermNo string `json:"term_no,omitempty"`
	// OutTradeNo 外部订单号
	OutTradeNo string `json:"out_trade_no,omitempty"`
	// OriOutTradeNo 原外部订单号
	OriOutTradeNo string `json:"ori_out_trade_no,omitempty"`
	// OriTransactionID 原平台订单号
	OriTransactionID string `json:"ori_transaction_id,omitempty"`
	// TotalFee 交易金额
	TotalFee string `json:"total_fee,omitempty"`
	// DeviceInfo 终端设备号
	DeviceInfo string `json:"device_info,omitempty"`
	// MchCreateIP 商户IP
	MchCreateIP string `json:"mch_create_ip,omitempty"`
	// TransAddress 交易地址
	TransAddress string `json:"trans_address,omitempty"`
	// AreaCode 交易地区码
	AreaCode string `json:"area_code,omitempty"`
	// Longitude 经度
	Longitude string `json:"longitude,omitempty"`
	// Latitude 纬度
	Latitude string `json:"latitude,omitempty"`
	// Remark 备注
	Remark string `json:"remark,omitempty"`
	// 原始请求映射数据
	rawRequestMap map[string]interface{} `json:"-"`
}

// NewAuthCompleteRefundRequest 创建预授权完成退款请求
func NewAuthCompleteRefundRequest() *AuthCompleteRefundRequest {
	return &AuthCompleteRefundRequest{}
}

// SetMchID 设置商户号
func (r *AuthCompleteRefundRequest) SetMchID(mchID string) *AuthCompleteRefundRequest {
	r.MchID = mchID
	return r
}

// SetTermNo 设置终端号
func (r *AuthCompleteRefundRequest) SetTermNo(termNo string) *AuthCompleteRefundRequest {
	r.TermNo = termNo
	return r
}

// SetOutTradeNo 设置外部订单号
func (r *AuthCompleteRefundRequest) SetOutTradeNo(outTradeNo string) *AuthCompleteRefundRequest {
	r.OutTradeNo = outTradeNo
	return r
}

// SetOriOutTradeNo 设置原外部订单号
func (r *AuthCompleteRefundRequest) SetOriOutTradeNo(oriOutTradeNo string) *AuthCompleteRefundRequest {
	r.OriOutTradeNo = oriOutTradeNo
	return r
}

// SetOriTransactionID 设置原平台订单号
func (r *AuthCompleteRefundRequest) SetOriTransactionID(oriTransactionID string) *AuthCompleteRefundRequest {
	r.OriTransactionID = oriTransactionID
	return r
}

// SetTotalFee 设置交易金额
func (r *AuthCompleteRefundRequest) SetTotalFee(totalFee string) *AuthCompleteRefundRequest {
	r.TotalFee = totalFee
	return r
}

// SetDeviceInfo 设置终端设备号
func (r *AuthCompleteRefundRequest) SetDeviceInfo(deviceInfo string) *AuthCompleteRefundRequest {
	r.DeviceInfo = deviceInfo
	return r
}

// SetMchCreateIP 设置商户IP
func (r *AuthCompleteRefundRequest) SetMchCreateIP(mchCreateIP string) *AuthCompleteRefundRequest {
	r.MchCreateIP = mchCreateIP
	return r
}

// SetTransAddress 设置交易地址
func (r *AuthCompleteRefundRequest) SetTransAddress(transAddress string) *AuthCompleteRefundRequest {
	r.TransAddress = transAddress
	return r
}

// SetAreaCode 设置交易地区码
func (r *AuthCompleteRefundRequest) SetAreaCode(areaCode string) *AuthCompleteRefundRequest {
	r.AreaCode = areaCode
	return r
}

// SetLongitude 设置经度
func (r *AuthCompleteRefundRequest) SetLongitude(longitude string) *AuthCompleteRefundRequest {
	r.Longitude = longitude
	return r
}

// SetLatitude 设置纬度
func (r *AuthCompleteRefundRequest) SetLatitude(latitude string) *AuthCompleteRefundRequest {
	r.Latitude = latitude
	return r
}

// SetRemark 设置备注
func (r *AuthCompleteRefundRequest) SetRemark(remark string) *AuthCompleteRefundRequest {
	r.Remark = remark
	return r
}

// SetRawRequestMap 设置原始请求映射数据
func (r *AuthCompleteRefundRequest) SetRawRequestMap(rawMap map[string]interface{}) *AuthCompleteRefundRequest {
	r.rawRequestMap = rawMap
	return r
}

// GetRawMap 获取原始映射数据
func (r *AuthCompleteRefundRequest) GetRawMap() (map[string]interface{}, bool) {
	return r.rawRequestMap, r.rawRequestMap != nil
}

// ToMap 转换为map
func (r *AuthCompleteRefundRequest) ToMap() (map[string]interface{}, error) {
	// 如果有原始映射数据，直接返回
	if rawMap, exists := r.GetRawMap(); exists {
		return rawMap, nil
	}

	// 构建基础请求数据
	requestMap := make(map[string]interface{})

	// 添加基础字段
	if r.MchID != "" {
		requestMap["mch_id"] = r.MchID
	}
	if r.TermNo != "" {
		requestMap["term_no"] = r.TermNo
	}
	if r.OutTradeNo != "" {
		requestMap["out_trade_no"] = r.OutTradeNo
	}
	if r.OriOutTradeNo != "" {
		requestMap["ori_out_trade_no"] = r.OriOutTradeNo
	}
	if r.OriTransactionID != "" {
		requestMap["ori_transaction_id"] = r.OriTransactionID
	}
	if r.TotalFee != "" {
		requestMap["total_fee"] = r.TotalFee
	}
	if r.DeviceInfo != "" {
		requestMap["device_info"] = r.DeviceInfo
	}
	if r.MchCreateIP != "" {
		requestMap["mch_create_ip"] = r.MchCreateIP
	}
	if r.TransAddress != "" {
		requestMap["trans_address"] = r.TransAddress
	}
	if r.AreaCode != "" {
		requestMap["area_code"] = r.AreaCode
	}
	if r.Longitude != "" {
		requestMap["longitude"] = r.Longitude
	}
	if r.Latitude != "" {
		requestMap["latitude"] = r.Latitude
	}
	if r.Remark != "" {
		requestMap["remark"] = r.Remark
	}

	// 合并基础请求数据
	baseMap, err := r.OrgBaseRequest.ToMap()
	if err != nil {
		return nil, err
	}

	for k, v := range baseMap {
		requestMap[k] = v
	}

	return requestMap, nil
}

// CheckRequiredParams 检查必需参数
func (r *AuthCompleteRefundRequest) CheckRequiredParams(config *core.Config) error {
	return r.OrgBaseRequest.CheckRequiredParams(config)
}

// ==================== 预授权完成退款响应 ====================

// AuthCompleteRefundResponse 预授权完成退款响应
type AuthCompleteRefundResponse struct {
	models.StandardResponse
	// Status 状态 2：成功 3：失败
	Status string `json:"status,omitempty"`
	// MchID 商户号
	MchID string `json:"mch_id,omitempty"`
	// TransactionID 平台订单号
	TransactionID string `json:"transaction_id,omitempty"`
	// OutTradeNo 外部订单号
	OutTradeNo string `json:"out_trade_no,omitempty"`
	// OriOutTradeNo 原外部订单号
	OriOutTradeNo string `json:"ori_out_trade_no,omitempty"`
	// OriTransactionID 原平台订单号
	OriTransactionID string `json:"ori_transaction_id,omitempty"`
	// OrderTime 订单时间
	OrderTime string `json:"order_time,omitempty"`
	// PayType 交易类型
	PayType string `json:"pay_type,omitempty"`
	// TotalFee 交易金额
	TotalFee interface{} `json:"total_fee,omitempty"`
	// TransTime 交易时间
	TransTime string `json:"trans_time,omitempty"`
}

// NewAuthCompleteRefundResponse 创建预授权完成退款响应
func NewAuthCompleteRefundResponse() *AuthCompleteRefundResponse {
	return &AuthCompleteRefundResponse{}
}
